package conjuntos;

class Celular {
	String marca, modelo;
	int numSerie;

	Celular(String marca, String modelo, int numSerie) {
		this.marca = marca;
		this.modelo = modelo;
		this.numSerie = numSerie;
	}

	public boolean equals(Object o) { //metodo equals compara conteudo de objetos
		if ((o instanceof Celular) && ((Celular) o).modelo == this.modelo)
			return true;
		else
			return false;
	}

	public int hashCode() { //metodo hashCode verifica se os dois objetos (classes wrappers)  
                                //Integer apontam para o mesmo endere�o
		return numSerie;
	}

	@Override
	public String toString() {
		return "Celular [marca=" + marca + ", modelo=" + modelo + ", numSerie="
				+ numSerie + "]";
	}

}

public class EqualsHashCode1 {

	public static void main(String[] args) {
		
		Celular c1 = new Celular("LG", "xpt", 123);
		Celular c2 = new Celular("Nokia", "xpt", 124);
		Celular c3 = new Celular("Samsung", "kpz", 123);
		System.out.println(c1);
		System.out.println(c2);
		System.out.println(c3);
		System.out.println();
		System.out.println("hashCode de c1 = " + c1.hashCode());
		System.out.println("hashCode de c2 = " + c2.hashCode());
		System.out.println("hashCode de c3 = " + c3.hashCode());
		System.out.println();
		System.out.println(c1.equals(c2));// true
		System.out.println(c2.equals(c3));// false
		System.out.println(c1.equals(c3));// false
		System.out.println(c1.hashCode() == c2.hashCode());// false
		System.out.println(c2.hashCode() == c3.hashCode());// false
		System.out.println(c1.hashCode() == c3.hashCode());// true
	}

}
